clear
graph drop _all
set scheme modern

cap cd "INSERT FOLDER PATH HERE"

use "BFS Data - Study 1.dta"

cap log close
log using "TPFC Results.log", replace

** Clean Data **

* The following people submitted baseline surveys well after the study had 
* concluded, but they appear in the download of the baseline data. So, we drop
* them.
drop if inlist( agentid,253985,649763,816921,866478,921609,1216610,1219504)

* Drop those without a primary time preference measure
drop if TimePreferenceFuture == ""

** Create Key Variables **

*Label main treatment variable
label define AltTreatmentCode 1 "Control" 2 "Restricted" 3 "Agency" 4 ///
	"WP - Early" 5 "WP - Delayed" 

* Indicate those subsisized
gen Subsidy = (AltTreatmentCode > 1) if !mi(AltTreatmentCode)

* Measure attrition
egen MaxWeek = max(Week), by(agentid)

* Create future-dated only time preference measure
gen timeexp2 = substr(TimePreferenceFuture,1,1)
gen timeexp = 1 if timeexp2 == "R"
gen timeexp3 = substr(TimePreferenceFuture,6,2)
gen timeexp4 = real(timeexp3)
replace timeexp = timeexp4 if timeexp == .
replace timeexp = timeexp - 1
labmask timeexp, values(TimePreferenceFuture)
drop timeexp2 timeexp3 timeexp4

* Create present vs. future time preference measure
gen timepb2 = substr(TimePreferencePresent,1,1)
gen timepb = 0 if timepb2 == "R"
gen timepb3 = substr(TimePreferencePresent,6,2)
gen timepb4 = real(timepb3)
replace timepb = timepb4 if timepb == .
labmask timepb, values(TimePreferencePresent)
drop timepb2 timepb3 timepb4

* Create time preference measure noise
gen timeimp2 = substr(TimePreferencePresentRepeat,1,1)
gen timeimp = 0 if timeimp2 == "R"
gen timeimp3 = substr(TimePreferencePresentRepeat,6,2)
gen timeimp4 = real(timeimp3)
replace timeimp = timeimp4 if timeimp == .
labmask timeimp, values(TimePreferencePresentRepeat)
drop timeimp2 timeimp3 timeimp4

* Need to standardize without over-weighting shoppers who appear more than once.
bysort agentid: gen First = (_n == 1)

* "Exponential": bigger is more patient
egen Exponential_1 = std(timeexp - 1) if First == 1

* "Exponential_q2": bigger is more patient, question 2
egen Exponential2_1 = std(timepb - 1) if First == 1

* "Exponential_q3": bigger is more patient, question 3
egen Exponential3_1 = std(timeimp - 1) if First == 1

* "Hyperbolic": bigger is more present biased
egen Hyperbolic_1 = std(timeexp - timepb) if First == 1

* "Noise": deviation from beginning of survey to end of survey
egen Noise_1 = std(timeimp - timepb) if First == 1

* "Hyp_Alt": using end of survey question to construct hyperbolicity
egen Hyp_Alt_1 = std(timeexp - timeimp) if First == 1

foreach var in Exponential Exponential2 Exponential3 Hyperbolic Noise Hyp_Alt {
	egen `var'=mean(`var'_1),  by(agentid)
}

* Create oridinal versions of patience and hyperbolicity
gen Exp_Level = 0 if timeexp == 0 & !mi(timeexp) & !mi(timepb)
replace Exp_Level = 1 if timeexp > 0 & timeexp < 26  & !mi(timeexp) & ///
	!mi(timepb)
replace Exp_Level = 2 if timeexp == 26  & !mi(timeexp) & !mi(timepb)

gen Hyp_Level = 0 if timepb > timeexp  & !mi(timeexp) & !mi(timepb)
replace Hyp_Level = 1 if timepb == timeexp & !mi(timeexp) & !mi(timepb)
replace Hyp_Level = 2 if timepb < timeexp & !mi(timeexp) & !mi(timepb)

* Calculate total food spending
replace NonFood = 0 if mi(NonFood)
gen TotalFood = ReceiptTotal - NonFood

replace Baseline_NonFood = 0 if mi(Baseline_NonFood)
gen TotalFood_Baseline = Baseline_ReceiptTotal - Baseline_NonFood

replace Endline_NonFood = 0 if mi(Endline_NonFood)
gen TotalFood_Endline = Endline_ReceiptTotal - Endline_NonFood

* If, for some reason, the total is missing, the non-food amount exceeds the  
* total, or if TFV + BG spending exceeds the total, but TFV + BG spending
* is recorded, we replace total food spending with TFV + BG spending
replace TotalFood = TotalTFV + TotalBG if (mi(ReceiptTotal) | TotalFood < 0 ///
	| TotalFood < (TotalTFV + TotalBG))
	
replace TotalFood_Baseline = Baseline_TotalTFV + Baseline_TotalBG if ///
	(mi(Baseline_ReceiptTotal) | TotalFood_Baseline < 0 | ///
	TotalFood_Baseline < (Baseline_TotalTFV + Baseline_TotalBG))
	
replace TotalFood_Endline = Endline_TotalTFV + Endline_TotalBG if ///
	(mi(Endline_ReceiptTotal) | TotalFood_Endline < 0 | ///
	TotalFood_Endline < (Endline_TotalTFV + Endline_TotalBG))
	
* Calculate TFV share
gen TFV_Ratio = (TotalTFV/TotalFood)

gen TFV_Ratio_Baseline = (Baseline_TotalTFV/TotalFood_Baseline)

gen TFV_Ratio_Endline = (Endline_TotalTFV/TotalFood_Endline)

* Set TFV share equal to zero if the receipt has no food
replace TFV_Ratio = 0 if TotalTFV == 0 & mi(TFV_Ratio)

replace TFV_Ratio_Baseline = 0 if Baseline_TotalTFV==0 & mi(TFV_Ratio_Baseline)

replace TFV_Ratio_Endline = 0 if Endline_TotalTFV==0 & mi(TFV_Ratio_Endline)

* Calculate BG share
gen BG_Ratio = (TotalBG/TotalFood)

gen BG_Ratio_Baseline = (Baseline_TotalBG/TotalFood_Baseline)

gen BG_Ratio_Endline = (Endline_TotalBG/TotalFood_Endline)

* Set BG share equal to zero if the receipt has no food
replace BG_Ratio = 0 if TotalBG == 0 & mi(BG_Ratio)

replace BG_Ratio_Baseline = 0 if Baseline_TotalBG == 0 & mi(BG_Ratio_Baseline)

replace BG_Ratio_Endline = 0 if Endline_TotalBG == 0 & mi(BG_Ratio_Endline)

* Calculate TFV-to-BG ratio
gen TFV_to_BG = TotalTFV/TotalBG

gen TFV_to_BG_Baseline = Baseline_TotalTFV/Baseline_TotalBG

gen TFV_to_BG_Endline = Endline_TotalTFV/Endline_TotalBG

* Set TFV-to-BG ratio equal to TFV/minimum observed BG value if BG is zero
replace TFV_to_BG = TotalTFV/0.24 if TotalBG == 0 & mi(TFV_to_BG)

replace TFV_to_BG_Baseline = Baseline_TotalTFV/0.24 if Baseline_TotalBG == 0 ///
	& mi(TFV_to_BG_Baseline)

replace TFV_to_BG_Endline = Endline_TotalTFV/0.24 if Endline_TotalBG==0 & ///
	mi(TFV_to_BG_Endline)
	
* Replace errant negative item values in diary with zeros
foreach var in BaselineDiary_BG BaselineDiary_TFV BaselineDiary_MeatDairy ///
	BaselineDiary_Others BaselineDiary_SweetBev BaselineDiary_Snacks ///
	EndlineDiary_BG EndlineDiary_TFV EndlineDiary_MeatDairy ///
	EndlineDiary_Others EndlineDiary_SweetBev EndlineDiary_Snacks {
	replace `var' = 0 if `var' < 0
}

* Make sure all entries are zeroed out when a diary doesn't contain it
egen BaselineDiary_any = rownonmiss(BaselineDiary_BG BaselineDiary_TFV  ///
	BaselineDiary_MeatDairy BaselineDiary_Others BaselineDiary_SweetBev  ///
	BaselineDiary_Snacks)
	
foreach var in BaselineDiary_BG BaselineDiary_TFV BaselineDiary_MeatDairy ///
	BaselineDiary_Others BaselineDiary_SweetBev BaselineDiary_Snacks {
	replace `var' = 0 if `var' == . & BaselineDiary_any > 0
}
	
egen EndlineDiary_any = rownonmiss(EndlineDiary_BG EndlineDiary_TFV  ///
	EndlineDiary_MeatDairy EndlineDiary_Others EndlineDiary_SweetBev  ///
	EndlineDiary_Snacks)

foreach var in EndlineDiary_BG EndlineDiary_TFV EndlineDiary_MeatDairy ///
	EndlineDiary_Others EndlineDiary_SweetBev EndlineDiary_Snacks {
	replace `var' = 0 if `var' == . & EndlineDiary_any > 0
}

* Calculate total food consumptiom
gen TotalFood_Diary_Baseline = BaselineDiary_BG + BaselineDiary_TFV + ///
	BaselineDiary_MeatDairy + BaselineDiary_Others + BaselineDiary_SweetBev ///
	+ BaselineDiary_Snacks

	
gen TotalFood_Diary_Endline = EndlineDiary_BG + EndlineDiary_TFV + ///
	EndlineDiary_MeatDairy + EndlineDiary_Others + EndlineDiary_SweetBev + ///
	EndlineDiary_Snacks
	
* Calculate TFV consuption share
gen TFV_Ratio_Diary_Baseline = (BaselineDiary_TFV/TotalFood_Diary_Baseline)

gen TFV_Ratio_Diary_Endline = (EndlineDiary_TFV/TotalFood_Diary_Endline)

* Set TFV share equal to zero if the diary has no categorizeable food
replace TFV_Ratio_Diary_Baseline = 0 if BaselineDiary_TFV == 0 & ///
	mi(TFV_Ratio_Diary_Baseline)

replace TFV_Ratio_Diary_Endline = 0 if EndlineDiary_TFV == 0 & ///
	mi(TFV_Ratio_Diary_Endline)
	
* Create healthy consumption share
gen H_Ratio_Diary_Baseline = (BaselineDiary_TFV + BaselineDiary_MeatDairy) / ///
	TotalFood_Diary_Baseline
	
gen H_Ratio_Diary_Endline = (EndlineDiary_TFV + EndlineDiary_MeatDairy) / ///
	TotalFood_Diary_Endline
	
* Set healthy share equal to zero if the diary has no categorizeable food
replace H_Ratio_Diary_Baseline = 0 if BaselineDiary_TFV == 0 & ///
	BaselineDiary_MeatDairy == 0 & mi(H_Ratio_Diary_Baseline) 
	
replace H_Ratio_Diary_Endline = 0 if EndlineDiary_TFV == 0 & ///
	EndlineDiary_MeatDairy == 0 & mi(H_Ratio_Diary_Baseline) 

* Calculate BG consumption share	
gen BG_Ratio_Diary_Baseline = (BaselineDiary_BG/TotalFood_Diary_Baseline)

gen BG_Ratio_Diary_Endline = (EndlineDiary_BG/TotalFood_Diary_Endline)

* Set BG share equal to zero if the diary has no categorizeable food
replace BG_Ratio_Diary_Baseline = 0 if BaselineDiary_BG == 0 & ///
	mi(BG_Ratio_Diary_Baseline)

replace BG_Ratio_Diary_Endline = 0 if EndlineDiary_BG == 0 & ///
	mi(BG_Ratio_Diary_Endline)
	
* Create unhealthy consumption share
gen U_Ratio_Diary_Baseline = (BaselineDiary_BG + BaselineDiary_Snacks + ///
	BaselineDiary_SweetBev)/TotalFood_Diary_Baseline
	
gen U_Ratio_Diary_Endline = (EndlineDiary_BG + EndlineDiary_Snacks + ///
	EndlineDiary_SweetBev)/TotalFood_Diary_Endline
	
* Set unhealthy share equal to zero if the diary has no categorizeable food
replace U_Ratio_Diary_Baseline = 0 if BaselineDiary_BG == 0 & ///
	BaselineDiary_Snacks == 0 & BaselineDiary_SweetBev == 0 & ///
	mi(U_Ratio_Diary_Baseline) 
	
replace U_Ratio_Diary_Endline = 0 if EndlineDiary_BG == 0 & ///
	EndlineDiary_Snacks == 0 & EndlineDiary_SweetBev == 0 & ///
	mi(U_Ratio_Diary_Endline) 
	
* Calculate TFV-to-BG consumption ratio
gen TFV_to_BG_Cons_Baseline = BaselineDiary_TFV/BaselineDiary_BG

gen TFV_to_BG_Cons_Endline = EndlineDiary_TFV/EndlineDiary_BG

* Set TFV-to-BG consumotion ratio equal to TFV if BG is zero
replace TFV_to_BG_Cons_Baseline = BaselineDiary_TFV if ///
	BaselineDiary_BG == 0 & mi(TFV_to_BG_Cons_Baseline)

replace TFV_to_BG_Cons_Endline = EndlineDiary_TFV if EndlineDiary_BG == 0 & ///
	mi(TFV_to_BG_Cons_Endline)
	
* Calculate H-to-U consumption ratio
gen H_to_U_Cons_Baseline = (BaselineDiary_TFV + BaselineDiary_MeatDairy) / ///
	(BaselineDiary_BG + BaselineDiary_Snacks + BaselineDiary_SweetBev)

gen H_to_U_Cons_Endline = (EndlineDiary_TFV + EndlineDiary_MeatDairy) / ///
	(EndlineDiary_BG + EndlineDiary_Snacks + EndlineDiary_SweetBev)

* Set TFV-to-BG consumotion ratio equal to TFV if BG is zero
replace H_to_U_Cons_Baseline = BaselineDiary_TFV + BaselineDiary_MeatDairy ///
	if BaselineDiary_BG == 0 & BaselineDiary_Snacks + ///
	BaselineDiary_SweetBev == 0 & mi(H_to_U_Cons_Baseline)

replace H_to_U_Cons_Endline = EndlineDiary_TFV + EndlineDiary_MeatDairy ///
	if EndlineDiary_BG == 0 & EndlineDiary_Snacks + ///
	EndlineDiary_SweetBev == 0 & mi(H_to_U_Cons_Endline)

** Setup Panel Data Structure **

egen id_count = count(1), by(agentid)
egen MinWeek = min(Week), by(agentid)
gen altweek1 = 1 if Week == MinWeek

expand 2 if altweek1 == 1, gen(dupe)
replace Week = 0 if altweek1 == 1 & dupe == 1
replace altweek1 = . if altweek1 == 1 & dupe == 1
drop dupe

expand 2 if altweek1 == 1, gen(dupe)
replace Week = 5 if altweek == 1 & dupe == 1
drop dupe 

egen base_only = max(Week), by(agentid) missing
drop if base_only == . & (Week > 0)

xtset agentid Week

** Fill in Baseline and Endline Variables **

replace TotalTFV = Baseline_TotalTFV if Week == 0
replace TotalTFV = Endline_TotalTFV if Week == 5

replace TotalBG = Baseline_TotalBG if Week == 0
replace TotalBG = Endline_TotalBG if Week == 5

replace TFV_Ratio = TFV_Ratio_Baseline if Week == 0
replace TFV_Ratio = TFV_Ratio_Endline if Week == 5

replace BG_Ratio = BG_Ratio_Baseline if Week == 0
replace BG_Ratio = BG_Ratio_Endline if Week == 5

replace TFV_to_BG = TFV_to_BG_Baseline if Week == 0
replace TFV_to_BG = TFV_to_BG_Endline if Week == 5

gen TFV_Cons = BaselineDiary_TFV if Week == 0
replace TFV_Cons = EndlineDiary_TFV if Week == 5

gen BG_Cons = BaselineDiary_BG if Week == 0
replace BG_Cons = EndlineDiary_BG if Week == 5

gen MD_Cons = BaselineDiary_MeatDairy if Week == 0
replace MD_Cons = EndlineDiary_MeatDairy if Week == 5

gen SN_Cons = BaselineDiary_Snacks if Week == 0
replace SN_Cons = EndlineDiary_Snacks if Week == 5

gen SB_Cons = BaselineDiary_SweetBev if Week == 0
replace SB_Cons = EndlineDiary_Sweet if Week == 5

gen TFV_Cons_Ratio = TFV_Ratio_Diary_Baseline if Week == 0
replace TFV_Cons_Ratio = TFV_Ratio_Diary_Endline if Week == 5

gen BG_Cons_Ratio = BG_Ratio_Diary_Baseline if Week == 0
replace BG_Cons_Ratio = BG_Ratio_Diary_Endline if Week == 5

gen TFV_to_BG_Cons = TFV_to_BG_Cons_Baseline if Week == 0 
replace TFV_to_BG_Cons = TFV_to_BG_Cons_Endline if Week == 5

gen H_Cons = BaselineDiary_TFV + BaselineDiary_MeatDairy if Week == 0
replace H_Cons = EndlineDiary_TFV + EndlineDiary_MeatDairy if Week == 5

gen U_Cons = BaselineDiary_BG + BaselineDiary_Snacks + ///
	BaselineDiary_SweetBev if Week == 0
replace U_Cons = EndlineDiary_BG + EndlineDiary_Snacks + ///
	EndlineDiary_SweetBev if Week == 5

gen H_Cons_Ratio = H_Ratio_Diary_Baseline if Week == 0
replace H_Cons_Ratio = H_Ratio_Diary_Endline if Week == 5

gen U_Cons_Ratio = U_Ratio_Diary_Baseline if Week == 0
replace U_Cons_Ratio = U_Ratio_Diary_Endline if Week == 5

gen H_to_U_Cons = H_to_U_Cons_Baseline if Week == 0 
replace H_to_U_Cons = H_to_U_Cons_Endline if Week == 5

** Section 2.1 **

* Count subjects
sum agentid if Week == 0

** Section 2.2 **

* Count those not advancing to treatment
sum agentid if Week == 0 & AltTreatmentCode == .

* Count those assigned to Control
sum agentid if Week == 0 & AltTreatmentCode == 1

* Count those assigned to a subsidy
sum agentid if Week == 0 & AltTreatmentCode > 1 & AltTreatmentCode != .

* Count those assigned to a subsidy choice
sum agentid if Week == 0 & AltTreatmentCode > 2 & AltTreatmentCode != .

* Count those assigned to a subsidy without choice
sum agentid if Week == 0 & AltTreatmentCode == 2 

** Section 3 **

* Count those advancing to treatment
sum agentid if Week == 0 & AltTreatmentCode != .

* Count study period shopping trips
sum agentid if Week > 0 & Week < 5

* Count those completing endline
sum agentid if Week == 5 & date2 != .

** Table 2 **

* Panel A: Time Preferences 
sum timeexp if Week == 0
sum timepb if Week == 0

* Panel B: Baseline Food Choice 
sum TotalTFV if Week == 0
sum TFV_Ratio if Week == 0
sum TFV_Cons if Week == 0
sum TFV_Cons_Ratio if Week == 0
sum H_Cons if Week == 0
sum H_Cons_Ratio if Week == 0
sum TotalBG if Week == 0
sum BG_Ratio if Week == 0
sum BG_Cons if Week == 0
sum BG_Cons_Ratio if Week == 0
sum U_Cons if Week == 0
sum U_Cons_Ratio if Week == 0

* Panel C: Food Choice
sum TotalTFV if Week > 0 & Week < 5 & AltTreatmentCode == 1
sum TFV_Ratio if Week > 0 & Week < 5 & AltTreatmentCode == 1
sum TotalTFV if Week > 0 & Week < 5 & AltTreatmentCode > 1
sum TFV_Ratio if Week > 0 & Week < 5 & AltTreatmentCode > 1
sum TFV if Week > 0 & Week < 5 & AltTreatmentCode > 2

** Table 3 **

* PANEL A: Healthy Food 

reg TotalTFV Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1

reg TFV_Ratio Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2

reg TFV_Cons Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3

reg TFV_Cons_Ratio Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e4

reg H_Cons Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e5

reg H_Cons_Ratio Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabT3A.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

* PANEL B: Unhealthy Food

reg TotalBG Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1

reg BG_Ratio Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2

reg BG_Cons Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3

reg BG_Cons_Ratio Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e4

reg U_Cons Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e5

reg U_Cons_Ratio Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabT3B.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

* Panel C: A/B 

reg TFV_to_BG Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1

reg TFV_to_BG_Cons Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2

reg H_to_U_Cons Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3

/*
estout e1 e2 e3 using Tables/TabT3C.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/
	
** Section 4.1 **

* Footnote 22: Meat and dairy consumption on their own 
	
reg MD_Cons Exponential Hyperbolic i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)

** Table 4 **

xtreg TotalTFV i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	i.Wave if Week > 0 & Week < 5 & AltTreatmentCode < 3, re cl(agentid)
est store e1
	
xtreg TFV_Ratio i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	i.Wave if Week > 0 & Week < 5 & AltTreatmentCode < 3, re cl(agentid)
est store e2

xtreg TotalTFV i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	i.Wave if Week > 0 & Week < 5, re cl(agentid)
est store e3
	
xtreg TFV_Ratio i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	i.Wave if Week > 0 & Week < 5, re cl(agentid)
est store e4

/*
estout e1 e2 e3 e4 using Tables/TabT4.tex, replace ///
	keep(1.Subsidy Exponential Hyperbolic 1.Subsidy#c.Exponential ///
		1.Subsidy#c.Hyperbolic _cons) ///
	varlabels(Exponential "Patience" Hyperbolic "Hyperbolicity" ///
		1.Subsidy#c.Exponential "Subsidy x Patience" ///
		1.Subsidy#c.Hyperbolic "Subsidy x Hyperbolicity" ///
		1.Subsidy "Subsidy" _cons Constant) ///
	order(1.Subsidy Exponential Hyperbolic 1.Subsidy#c.Exponential ///
		1.Subsidy#c.Hyperbolic _cons) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) stats(N_clust N, f(0) ///
	labels("Clusters" "Observations")) style(tex) mlabels(none) collabels(none) 
*/

** Table 5 **

xtreg TFV Exponential Hyperbolic i.Wave if AltTreatmentCode > 2 & ///
	Week > 0 & Week < 5, cl(agentid) re

probit TFV Exponential Hyperbolic i.Wave if AltTreatmentCode > 2 & Week > 0 ///
	& Week < 5, cl(agentid)
margins, at(Exponential = 0 Hyperbolic = 0)
margins, dydx(Exponential Hyperbolic) at(Exponential = 0 Hyperbolic = 0)

** Figure A1 **

gen timeexp1 = timeexp + 1

hist timeexp1 if Week == 0, start(0.5) width(1) percent ///
	xlabel(1 2 3 5 7 9 11 13 16 19 23 27) xtitle(Weeks Until Redemption) ///
	barwidth(.9) fcolor(navy%40) lcolor(navy) lwidth(medium) legend(off) ///
	ytitle("") ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%") ///
	subtitle("Fraction", pos(11) span) ///
	name(FigA1, replace)
*graph export Graphics/FigA1.pdf, as(pdf) replace

** Figure A2 **

hist timepb if Week == 0, start(-0.5) width(1) percent ///
	xlabel(0 1 2 4 6 8 10 12 15 18 22 26) xtitle(Weeks Until Redemption) ///
	barwidth(.9) fcolor(navy%40) lcolor(navy) lwidth(medium) legend(off) ///
	ytitle("") ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%") ///
	subtitle("Fraction", pos(11) span) ///
	name(FigA2, replace)
*graph export Graphics/FigA2.pdf, as(pdf) replace

** Figure A3 **

* Create log count variable to deal with mass at zero
gen hyp = timeexp - timepb
egen hyp_count = count(1) if Week == 0, by(hyp)
replace hyp_count = ln(hyp_count + 1)

twoway bar hyp_count hyp if hyp < 0 || ///
	bar hyp_count hyp if hyp == 0 || ///
	bar hyp_count hyp if hyp > 0, ///
		xlabel(-25(5)25) xtick(-26(1)26) ///
		xtitle("Difference in Weeks Until Redemption") ///
		ylabel(0 "0" 0.69 "1" 2.4 "10" 4.62 "100") ///
		ytitle("Count (log scale + 1)") ///
		legend(label(1 Future-focused) label(2 Time-stationary) ///
			label(3 Present-focused) position(2) ring(0)) ///
	name(FigA3, replace)
*graph export Graphics/FigA3.pdf, as(pdf) replace

** Table A1 **

* Panel A: Full Sample
tab Exp_Level Hyp_Level if Week == 0

* Panel B: Intermediate patience only
sum Exponential if Exp_Level == 1 & Week == 0, d
gen Exp_Qtile = 1 if Exponential <= `r(p25)' & Exp_Level == 1
replace Exp_Qtile = 2 if Exponential > `r(p25)' & Exponential <= `r(p50)' & ///
	Exp_Level == 1
replace Exp_Qtile = 3 if Exponential > `r(p50)' & Exponential <= `r(p75)' & ///
	Exp_Level == 1
replace Exp_Qtile = 4 if Exponential > `r(p75)' & Exp_Level == 1

tab Exp_Qtile Hyp_Level if Exp_Level == 1 & Week == 0

** Figure A4 **

gen TotalTFV_Alt = TotalTFV
replace TotalTFV_Alt = 44.1 if TotalTFV_Alt>40

twoway hist TotalTFV_Alt if (AltTreatmentCode == 1 | Week == 0), ///
	width(4) ///
	start(0) ///
	fraction ///
	barwidth(3.9) ///
	fcolor(navy%40) ///
	lcolor(navy) ///
	lwidth(medium) ///
	legend(off) ///
	xlabel(0 "$0" 10 "$10" 20 "$20" 30 "$30" 40 "$40" 46 ">$40") ///
	xtitle(Total Fruit and Vegetable Spending) ///
	ytitle("") ///
	ylabel(0 "0%" .20 "20%" .40 "40%" .60 "60%" .80 "80%") ///
	subtitle("Fraction", pos(11) span) xsize(8) ///
	name(FigA4, replace)
*graph export Graphics/FigA4.pdf, as(pdf) replace

** Figure A5 **

gen TFV_Cons_2 = TFV_Cons
replace TFV_Cons_2 = 10 if TFV_Cons_2>10 & !mi(TFV_Cons_2)

twoway hist TFV_Cons_2 if (AltTreatmentCode == 1 | Week == 0), ///
	discrete ///
	start(0) ///
	fraction ///
	barwidth(.9) ///
	fcolor(navy%40) ///
	lcolor(navy) ///
	lwidth(medium)  ///
	legend(off) ///
	xlabel(0 2 4 6 8 10 "10+") ///
	xtitle(Total Fruit and Vegetable Consumption) ///
	ytitle("") ///
	ylabel(0 "0%" .05 "5%" .10 "10%" .15 "15%" .20 "20%") ///
	subtitle("Fraction", pos(11) span) xsize(8) ///
	name(FigA5, replace)
*graph export Graphics/FigA5.pdf, as(pdf) replace

** Figure A6 **

gen TotalBG_Alt = TotalBG
replace TotalBG_Alt = 44.1 if TotalBG_Alt>40

twoway hist TotalBG_Alt if (AltTreatmentCode == 1 | Week == 0), ///
	width(4) ///
	start(0) ///
	fraction ///
	barwidth(3.9) ///
	fcolor(navy%40) ///
	lcolor(navy) ///
	lwidth(medium) ///
	legend(off) ///
	xlabel(0 "$0" 10 "$10" 20 "$20" 30 "$30" 40 "$40" 46 ">$40") ///
	xtitle(Total Baked Good Spending) ///
	ytitle("") ///
	ylabel(0 "0%" .20 "20%" .40 "40%" .60 "60%" .80 "80%") ///
	subtitle("Fraction", pos(11) span) xsize(8) ///
	name(FigA6, replace)
*graph export Graphics/FigA6.pdf, as(pdf) replace

** Figure A7 **

gen BG_Cons_2 = BG_Cons
replace BG_Cons_2 = 10 if BG_Cons_2>10 & !mi(BG_Cons_2)

twoway hist BG_Cons_2 if (AltTreatmentCode == 1 | Week == 0), ///
	discrete ///
	start(0) ///
	fraction ///
	barwidth(.9) ///
	fcolor(navy%40) ///
	lcolor(navy) ///
	lwidth(medium)  ///
	legend(off) ///
	xlabel(0 2 4 6 8 10 "10+") ///
	xtitle(Total Baked Good Consumption) ///
	ytitle("") ///
	ylabel(0 "0%" .05 "5%" .10 "10%" .15 "15%" .20 "20%") ///
	subtitle("Fraction", pos(11) span) xsize(8) ///
	name(FigA7, replace)
*graph export Graphics/FigA7.pdf, as(pdf) replace

** Table A2 **

egen TFV_Purchase_STD = std(TotalTFV)
egen TFV_Consumption_STD = std(TFV_Cons)

gen ConsumptionConsistency = TFV_Consumption_STD - TFV_Purchase_STD

reg ConsumptionConsistency Exponential Hyperbolic i.Wave ///
	if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e1
	
egen TFV_Purchase_Ratio_STD = std(TFV_Ratio)
egen TFV_Consumption_Ratio_STD = std(TFV_Cons_Ratio)

gen ConsumptionConsistency2 = TFV_Consumption_Ratio_STD - TFV_Purchase_Ratio_STD

reg ConsumptionConsistency2 Exponential Hyperbolic i.Wave ///
	if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e2
	
/*
estout e1 e2 using Tables/TabA2.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

** Table A3 **

replace MaxWeek = 0 if MaxWeek == .

reg MaxWeek TotalTFV if Week == 0, r
est store e1

reg MaxWeek TFV_Cons if Week == 0, r
est store e2

egen TFV_mean1 = mean(TFV) if Week > 0 & Week < 5 & AltTreatmentCode > 2, ///
	by(agentid)
egen TFV_mean = mean(TFV_mean1), by(agentid)

reg MaxWeek TFV_mean if Week == 0, r
est store e3

/*
estout e1 e2 e3 using Tables/TabA3.tex, replace ///
	keep(TotalTFV TFV_Cons TFV_mean) ///
	varlabels(TotalTFV "Baseline FV spending" TFV_Cons ///
		"Baseline FV consumption from diary" TFV_mean ///
		"Selection rate of healthy subsidy") ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N, f(0) labels("Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

** Table A4 **

gen urban = (CitySize > 2)
gen kids = (Children > 0)

* PANEL A: Healthy Food

reg TotalTFV Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1

reg TFV_Ratio Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2

reg TFV_Cons Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3

reg TFV_Cons_Ratio Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e4

reg H_Cons Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e5

reg H_Cons_Ratio Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA4A.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

* PANEL B: Unhealthy Food

reg TotalBG Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1

reg BG_Ratio Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2

reg BG_Cons Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3

reg BG_Cons_Ratio Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e4

reg U_Cons Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e5

reg U_Cons_Ratio Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA4B.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/
	
* Panel C: A/B

reg TFV_to_BG Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1

reg TFV_to_BG_Cons Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2

reg H_to_U_Cons Exponential Hyperbolic i.Wave SNAP urban kids ///
	HouseholdSize PrimaryShopper Male if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3

/*
estout e1 e2 e3 using Tables/TabA4C.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

** Table A5 **

egen afford_fv = group(AffordTFV)
egen foodsec = group(FoodSecure)

* PANEL A: Healthy Food

reg TotalTFV Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e1

reg TFV_Ratio Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e2

reg TFV_Cons Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e3

reg TFV_Cons_Ratio Exponential Hyperbolic afford_fv foodsec SNAP ///
	i.HouseholdSize i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e4

reg H_Cons Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e5

reg H_Cons_Ratio Exponential Hyperbolic afford_fv foodsec SNAP ///
	i.HouseholdSize i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA5A.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/
	
* PANEL B: Unhealthy Food

reg TotalBG Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e1

reg BG_Ratio Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e2

reg BG_Cons Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e3

reg BG_Cons_Ratio Exponential Hyperbolic afford_fv foodsec SNAP ///
	i.HouseholdSize i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e4

reg U_Cons Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e5

reg U_Cons_Ratio Exponential Hyperbolic afford_fv foodsec SNAP ///
	i.HouseholdSize i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA5A.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

* Panel C: A/B

reg TFV_to_BG Exponential Hyperbolic afford_fv foodsec SNAP i.HouseholdSize ///
	i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e1

reg TFV_to_BG_Cons Exponential Hyperbolic afford_fv foodsec SNAP ///
	i.HouseholdSize i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e2

reg H_to_U_Cons Exponential Hyperbolic afford_fv foodsec SNAP ///
	i.HouseholdSize i.Wave if AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e3

/*
estout e1 e2 e3 using Tables/TabA5C.tex, replace ///
	keep(Exponential Hyperbolic _cons) ///
	varlabels(Exponential Patience Hyperbolic Hyperbolicity _cons Constant) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

** Table A6 **

xtreg TotalTFV i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	SNAP urban kids HouseholdSize PrimaryShopper Male i.Wave if Week > 0 & ///
	Week < 5 & AltTreatmentCode < 3, re cl(agentid)
est store e1
	
xtreg TFV_Ratio i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	SNAP urban kids HouseholdSize PrimaryShopper Male i.Wave if Week > 0 & ///
	Week < 5 & AltTreatmentCode < 3, re cl(agentid)
est store e2

xtreg TotalTFV i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	SNAP urban kids HouseholdSize PrimaryShopper Male i.Wave if Week > 0 & ///
	Week < 5, re cl(agentid)
est store e3
	
xtreg TFV_Ratio i.Subsidy##c.Exponential i.Subsidy##c.Hyperbolic ///
	SNAP urban kids HouseholdSize PrimaryShopper Male i.Wave if Week > 0 & ///
	Week < 5, re cl(agentid)
est store e4

/*
estout e1 e2 e3 e4 using Tables/TabT4.tex, replace ///
	keep(1.Subsidy Exponential Hyperbolic 1.Subsidy#c.Exponential ///
		1.Subsidy#c.Hyperbolic _cons) ///
	varlabels(Exponential "Patience" Hyperbolic "Hyperbolicity" ///
		1.Subsidy#c.Exponential "Subsidy x Patience" ///
		1.Subsidy#c.Hyperbolic "Subsidy x Hyperbolicity" ///
		1.Subsidy "Subsidy" _cons Constant) ///
	order(1.Subsidy Exponential Hyperbolic 1.Subsidy#c.Exponential ///
		1.Subsidy#c.Hyperbolic _cons) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) stats(N_clust N, f(0) ///
	labels("Clusters" "Observations")) style(tex) mlabels(none) collabels(none) 
*/

** Table A7 **

xtreg TFV Exponential Hyperbolic SNAP urban kids HouseholdSize ///
	PrimaryShopper Male i.Wave if AltTreatmentCode > 2 & Week > 0 & Week < 5, ///
	cl(agentid) re

probit TFV Exponential Hyperbolic SNAP urban kids HouseholdSize ///
	PrimaryShopper Male i.Wave if AltTreatmentCode > 2 & Week > 0 & ///
	Week < 5, cl(agentid)
margins, at(Exponential = 0 Hyperbolic = 0)
margins, dydx(Exponential Hyperbolic) at(Exponential = 0 Hyperbolic = 0)

** Table A8 **

reg TotalTFV ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg TFV_Ratio ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg TFV_Cons ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg TFV_Cons_Ratio ib1.Exp_Level ib1.Hyp_Level i.Wave if ///
	AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e4
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg H_Cons ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e5
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg H_Cons_Ratio ib1.Exp_Level ib1.Hyp_Level i.Wave if ///
	AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e6
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA8.tex, replace ///
	keep(0.Exp_Level 2.Exp_Level 0.Hyp_Level 2.Hyp_Level _cons) ///
	varlabels(0.Exp_Level "Least patient option" ///
		2.Exp_Level "Most patient option" ///
		0.Hyp_Level "Future-focused" ///
		2.Hyp_Level "Present-focused" ///
		_cons Constant) ///
	order(_cons 2.Exp_Level 0.Exp_Level 0.Hyp_Level 2.Hyp_Level) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none) 
*/

** Figure A8 **

egen LevelMean = mean(TotalTFV) if AltTreatmentCode==1 | Week==0, by(Exp_Level)
egen LevelSD = sd(TotalTFV) if AltTreatmentCode==1 | Week==0, by(Exp_Level)
egen LevelCount = total(1) if AltTreatmentCode==1 | Week==0, by(Exp_Level)
gen LB = LevelMean-1.96*LevelSD/sqrt(LevelCount)
gen UB = LevelMean+1.96*LevelSD/sqrt(LevelCount)

twoway bar LevelMean Exp_Level if AltTreatmentCode==1 | Week==0, ///
		barwidth(0.6) || ///
	rcap LB UB Exp_Level if AltTreatmentCode==1 | Week==0, lcolor(black) ///
		ylabel(0(2)6) ///
	legend(off) ytitle("Fruit and Vegetable Spending ($)") ///
	xlabel(0 "Least Patient" 1 "Intermediate" 2 "Most Patient") xtitle("") ///
	name(exp_exp, replace) subtitle(Panel A: Spending & Patience) ///
	nodraw

egen LevelMean2 = mean(TFV_Cons) if AltTreatmentCode==1 | Week==0, by(Exp_Level)
egen LevelSD2 = sd(TFV_Cons) if AltTreatmentCode==1 | Week==0, by(Exp_Level)
egen LevelCount2 = total(1) if AltTreatmentCode==1 | Week==0, by(Exp_Level)
gen LB2 = LevelMean2-1.96*LevelSD2/sqrt(LevelCount2)
gen UB2 = LevelMean2+1.96*LevelSD2/sqrt(LevelCount2)

twoway bar LevelMean2 Exp_Level if AltTreatmentCode==1 | Week==0, ///
		barw(0.6) || ///
	rcap LB2 UB2 Exp_Level if AltTreatmentCode==1 | Week==0, ///
		lcolor(black) ylabel(0(1)3) ///
	legend(off) ytitle("Fruit and Vegetable Consumption (items)") ///
	xlabel(0 "Least Patient" 1 "Intermediate" 2 "Most Patient") xtitle("") ///
	name(exp_cons, replace) subtitle(Panel C: Consumption & Patience) ///
	nodraw

egen LevelMean3 = mean(TotalTFV) if AltTreatmentCode==1 | Week==0, by(Hyp_Level)
egen LevelSD3 = sd(TotalTFV) if AltTreatmentCode==1 | Week==0, by(Hyp_Level)
egen LevelCount3 = total(1) if AltTreatmentCode==1 | Week==0, by(Hyp_Level)
gen LB3 = LevelMean3-1.96*LevelSD3/sqrt(LevelCount3)
gen UB3 = LevelMean3+1.96*LevelSD3/sqrt(LevelCount3)

twoway bar LevelMean3 Hyp_Level if AltTreatmentCode==1 | Week==0, ///
		barw(0.6) || ///
	rcap LB3 UB3 Hyp_Level if AltTreatmentCode==1 | Week==0, ///
		lcolor(black) ylabel(0(2)6) ///
	legend(off) ytitle("") ///
	xlabel(0 "Future-Focused" 1 "Time Stationary" 2 "Present-Focused") ///
	xtitle("") name(hyp_exp, replace) /// 
	subtitle(Panel B: Spending & Hyperbolicity) ///
	nodraw

egen LevelMean4 = mean(TFV_Cons) if AltTreatmentCode==1 | Week==0, by(Hyp_Level)
egen LevelSD4 = sd(TFV_Cons) if AltTreatmentCode==1 | Week==0, by(Hyp_Level)
egen LevelCount4 = total(1) if AltTreatmentCode==1 | Week==0, by(Hyp_Level)
gen LB4 = LevelMean4-1.96*LevelSD4/sqrt(LevelCount4)
gen UB4 = LevelMean4+1.96*LevelSD4/sqrt(LevelCount4)

twoway bar LevelMean4 Hyp_Level if AltTreatmentCode==1 | Week==0, ///
		barw(0.6) || ///
	rcap LB4 UB4 Hyp_Level if AltTreatmentCode==1 | Week==0, ///
		lcolor(black) ylabel(0(1)3) ///
	legend(off) ytitle("") ///
	xlabel(0 "Future-Focused" 1 "Time Stationary" 2 "Present-Focused") ///
	xtitle("") name(hyp_cons, replace) ///
	subtitle(Panel D: Consumption & Hyperbolicity) ///
	nodraw

graph combine exp_exp hyp_exp exp_cons hyp_cons, ///
	name(FigA8, replace)
*graph export Graphics/FigA8.pdf, as(pdf) replace


** Table A9 **

reg TotalBG ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg BG_Ratio ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e2
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg BG_Cons ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg BG_Cons_Ratio ib1.Exp_Level ib1.Hyp_Level i.Wave if ///
	AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e4
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg U_Cons ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e5
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg U_Cons_Ratio ib1.Exp_Level ib1.Hyp_Level i.Wave if ///
	AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e6
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA9.tex, replace ///
	keep(0.Exp_Level 2.Exp_Level 0.Hyp_Level 2.Hyp_Level _cons) ///
	varlabels(0.Exp_Level "Least patient option" ///
		2.Exp_Level "Most patient option" ///
		0.Hyp_Level "Future-focused" ///
		2.Hyp_Level "Present-focused" ///
		_cons Constant) ///
	order(_cons 2.Exp_Level 0.Exp_Level 0.Hyp_Level 2.Hyp_Level) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none) 
*/

** Table A10 **

reg TFV_to_BG ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e1
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg TFV_to_BG_Cons ib1.Exp_Level ib1.Hyp_Level i.Wave if ///
	AltTreatmentCode == 1 | Week == 0, cl(agentid)
est store e2
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

reg H_to_U_Cons ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode == 1 | ///
	Week == 0, cl(agentid)
est store e3
test 0.Exp_Level = 2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level

/*
estout e1 e2 e3 using Tables/TabA10.tex, replace ///
	keep(0.Exp_Level 2.Exp_Level 0.Hyp_Level 2.Hyp_Level _cons) ///
	varlabels(0.Exp_Level "Least patient option" ///
		2.Exp_Level "Most patient option" ///
		0.Hyp_Level "Future-focused" ///
		2.Hyp_Level "Present-focused" ///
		_cons Constant) ///
	order(_cons 2.Exp_Level 0.Exp_Level 0.Hyp_Level 2.Hyp_Level) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

** Table A11 **

reg TotalTFV i.Subsidy##ib1.Exp_Level i.Subsidy##ib1.Hyp_Level i.Wave if ///
	Week > 0 & Week < 5 & AltTreatmentCode < 3, cl(agentid)
est store e1
test 0.Exp_Level = 2.Exp_Level
test 1.Subsidy#0.Exp_Level = 1.Subsidy#2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level
test 1.Subsidy#0.Hyp_Level = 1.Subsidy#2.Hyp_Level

reg TFV_Ratio i.Subsidy##ib1.Exp_Level i.Subsidy##ib1.Hyp_Level i.Wave if ///
	Week > 0 & Week < 5 & AltTreatmentCode < 3, cl(agentid)
est store e2
test 0.Exp_Level = 2.Exp_Level
test 1.Subsidy#0.Exp_Level = 1.Subsidy#2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level
test 1.Subsidy#0.Hyp_Level = 1.Subsidy#2.Hyp_Level

reg TotalTFV i.Subsidy##ib1.Exp_Level i.Subsidy##ib1.Hyp_Level i.Wave if ///
	Week > 0 & Week < 5, cl(agentid)
est store e3
test 0.Exp_Level = 2.Exp_Level
test 1.Subsidy#0.Exp_Level = 1.Subsidy#2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level
test 1.Subsidy#0.Hyp_Level = 1.Subsidy#2.Hyp_Level

reg TFV_Ratio i.Subsidy##ib1.Exp_Level i.Subsidy##ib1.Hyp_Level i.Wave if ///
	Week > 0 & Week < 5, cl(agentid)
est store e4
test 0.Exp_Level = 2.Exp_Level
test 1.Subsidy#0.Exp_Level = 1.Subsidy#2.Exp_Level
test 0.Hyp_Level = 2.Hyp_Level
test 1.Subsidy#0.Hyp_Level = 1.Subsidy#2.Hyp_Level

/*
estout e1 e2 e3 e4 using Tables/TabA11.tex, replace ///
	keep(0.Exp_Level 2.Exp_Level 0.Hyp_Level 2.Hyp_Level ///
		1.Subsidy#0.Exp_Level 1.Subsidy#2.Exp_Level ///
		1.Subsidy#0.Hyp_Level 1.Subsidy#2.Hyp_Level 1.Subsidy _cons) ///
	varlabels(0.Exp_Level "Least patient option" ///
		2.Exp_Level "Most patient option" 0.Hyp_Level "Future-focused" ///
		2.Hyp_Level "Present-focused" ///
		1.Subsidy#0.Exp_Level "Least patient option $\times$ subsidy" ///
		1.Subsidy#2.Exp_Level "Most patient option $\times$ subsidy" ///
		1.Subsidy#0.Hyp_Level "Future-focused $\times$ subsidy" ///
		1.Subsidy#2.Hyp_Level "Present-focused $\times$ subsidy" ///
		1.Subsidy "Subsidy" _cons Constant) ///
	order(_cons 1.Subsidy 2.Exp_Level 0.Exp_Level 1.Subsidy#2.Exp_Level ///
		1.Subsidy#0.Exp_Level 0.Hyp_Level 2.Hyp_Level ///
		1.Subsidy#0.Hyp_Level 1.Subsidy#2.Hyp_Level) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stardrop(_cons) stats(N_clust N, f(0) ///
	labels("Clusters" "Observations")) style(tex) mlabels(none) collabels(none) 
*/
	
** Table A12 **

reg TFV ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode > 2 & ///
	Week > 0 & Week < 5, cl(agentid)
test i0.Exp_Level = i2.Exp_Level
test i0.Hyp_Level = i2.Hyp_Level

probit TFV ib1.Exp_Level ib1.Hyp_Level i.Wave if AltTreatmentCode > 2 & ///
	Week > 0 & Week < 5, cl(agentid)
margins, at(Exp_Level = 1 Hyp_Level = 1)
margins, dydx(i.Exp_Level i.Hyp_Level) at(Exp_Level = 1 Hyp_Level = 1)
test i0.Exp_Level = i2.Exp_Level
test i0.Hyp_Level = i2.Hyp_Level

** Table A13 **

* Triple the data to run the stacked regression
expand 2, gen(rep1)
expand 2, gen(rep2)
gen rep = 1 if rep1 == 0 & rep2 == 0
replace rep = 2 if rep1 == 0 & rep2 == 1
replace rep = 3 if rep1 == 1 & rep2 == 0
drop if rep == .

* Define the explanatory variable in each replication for the hyperbolicity IV
gen indep = Hyperbolic if rep == 1 
replace indep = Hyp_Alt if rep == 2

* Define the instrumental variable in each replication for the hyperbolicity IV
gen inst = Hyp_Alt if rep == 1 
replace inst = Hyperbolic if rep == 2

* PANEL A: Healthy Food

ivregress 2sls TotalTFV (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e1
	
ivregress 2sls TFV_Ratio (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e2

ivregress 2sls TFV_Cons (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e3

ivregress 2sls TFV_Cons_Ratio (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e4

ivregress 2sls H_Cons (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e5

ivregress 2sls H_Cons_Ratio (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA13A.tex, replace ///
	keep(indep Exponential) ///
	varlabels(indep Hyperbolicity Exponential Patience) ///
	order(Exponential indep) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

* PANEL B: Unhealthy Food

ivregress 2sls TotalBG (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e1
	
ivregress 2sls BG_Ratio (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e2

ivregress 2sls BG_Cons (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e3

ivregress 2sls BG_Cons_Ratio (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e4

ivregress 2sls U_Cons (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e5

ivregress 2sls U_Cons_Ratio (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA13B.tex, replace ///
	keep(indep Exponential) ///
	varlabels(indep Hyperbolicity Exponential Patience) ///
	order(Exponential indep) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/	

* PANEL C: A/B

ivregress 2sls TFV_to_BG (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e1
	
ivregress 2sls TFV_to_BG_Cons (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e2

ivregress 2sls H_to_U_Cons (indep = inst) Exponential i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e3

/*
estout e1 e2 e3 using Tables/TabA13C.tex, replace ///
	keep(indep Exponential) ///
	varlabels(indep Hyperbolicity Exponential Patience) ///
	order(Exponential indep) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

** Table A14 **

* Define the explanatory variable in each replication for the patience IV
gen indep_pat = Exponential if rep == 1 
replace indep_pat = Exponential2 if rep == 2
replace indep_pat = Exponential3 if rep == 3

* Define the instrumental variables in each replication for the patience IV
gen inst_pat1 = Exponential2 if rep == 1 
replace inst_pat1 = Exponential if rep == 2
replace inst_pat1 = Exponential if rep == 3

gen inst_pat2 = Exponential3 if rep == 1 
replace inst_pat2 = Exponential3 if rep == 2
replace inst_pat2 = Exponential2 if rep == 3

* PANEL A: Healthy Food

ivregress 2sls TotalTFV (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e1
	
ivregress 2sls TFV_Ratio (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e2

ivregress 2sls TFV_Cons (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e3

ivregress 2sls TFV_Cons_Ratio (indep_pat = inst_pat1 inst_pat2) i.Wave ///
	ibn.rep if AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e4

ivregress 2sls H_Cons (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e5

ivregress 2sls H_Cons_Ratio (indep_pat = inst_pat1 inst_pat2) i.Wave ///
	ibn.rep if AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA14A.tex, replace ///
	keep(indep_pat) ///
	varlabels(indep_pat Patience) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

* PANEL B: Unhealthy Food

ivregress 2sls TotalBG (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e1
	
ivregress 2sls BG_Ratio (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e2

ivregress 2sls BG_Cons (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e3

ivregress 2sls BG_Cons_Ratio (indep_pat = inst_pat1 inst_pat2) i.Wave ///
	ibn.rep if AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e4

ivregress 2sls U_Cons (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e5

ivregress 2sls U_Cons_Ratio (indep_pat = inst_pat1 inst_pat2) i.Wave ///
	ibn.rep if AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e6

/*
estout e1 e2 e3 e4 e5 e6 using Tables/TabA14B.tex, replace ///
	keep(indep_pat) ///
	varlabels(indep_pat Patience) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

* PANEL C: A/B

ivregress 2sls TFV_to_BG (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep if ///
	AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e1
	
ivregress 2sls TFV_to_BG_Cons (indep_pat = inst_pat1 inst_pat2) i.Wave ///
	ibn.rep if AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e2

ivregress 2sls H_to_U_Cons (indep_pat = inst_pat1 inst_pat2) i.Wave ibn.rep ///
	if AltTreatmentCode == 1 | Week == 0, nocons cl(agentid)
est store e3

/*
estout e1 e2 e3 using Tables/TabA14C.tex, replace ///
	keep(indep_pat) ///
	varlabels(indep_pat Patience) ///
	cells(b(star f(3)) se(f(3) par)) starlevels(* 0.1 ** 0.05 *** 0.01) ///
	stats(N_clust N, f(0) labels("Clusters" "Observations")) ///
	style(tex) mlabels(none) collabels(none)
*/

log close

